const KeyUserToken = 'userToken'
const KeyWalletAddress = 'walletAddress'
const KeyUID = 'uid'
const KeyReferToken = 'referToken'
const KeyExpiration = 'expiration'

export function getToken() {
    return localStorage.getItem(KeyUserToken) || ''
}

export function getReferToken() {
    return localStorage.getItem(KeyReferToken) || ''
}

export function setToken(value) {
    if (typeof value !== 'string') {
        throw Error('can\'t set token to ' + typeof value)
    }
    localStorage.setItem(KeyUserToken, value)
    return value
}

export function setReferToken(value) {
    if (typeof value !== 'string') {
        throw Error('can\'t set refer_token to ' + typeof value)
    }
    localStorage.setItem(KeyReferToken, value)
    return true
}

export function getWalletAddress() {
    return localStorage.getItem(KeyWalletAddress) || ''
}

export function setWalletAddress(value) {
    if (typeof value !== 'string') {
        throw Error('can\'t set walletAddress to ' + typeof value)
    }
    localStorage.setItem(KeyWalletAddress, value)
}

export function setUid(value) {
    if (typeof value !== 'string') {
        throw Error('can\'t set uid to ' + typeof value)
    }
    localStorage.setItem(KeyUID, value)
}

export function getUid() {
    return localStorage.getItem(KeyUID)
}

export function clearData() {
    localStorage.removeItem(KeyUserToken)
    localStorage.removeItem(KeyWalletAddress)
    localStorage.removeItem(KeyUID)
}

export function setExpiration(timeStamp) {
    localStorage.setItem(KeyExpiration, timeStamp)
}

export function getExpiration() {
    return localStorage.getItem(KeyExpiration)
}
